package com.sina.weibo.sdk.web.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.View;

public class WbSdkProgressBar extends View {
    private final int ʻ;
    private double ʻॱ;
    private float ʼ;
    private float ʽ;
    private int ˊ;
    private float ˊॱ;
    private int ˋ;
    private long ˋॱ;
    private RectF ˎ;
    private int ˏ;
    private double ˏॱ;
    private long ͺ;
    int ॱ;
    private long ॱˊ;
    private boolean ॱˋ;
    private Paint ॱॱ;
    private Handler ॱᐝ;
    private final int ᐝ;
    private boolean ᐝॱ;

    public WbSdkProgressBar(Context context) {
        this(context, null);
    }

    public WbSdkProgressBar(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public WbSdkProgressBar(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ʻ = 20;
        this.ᐝ = 300;
        this.ॱˊ = 0;
        this.ˊॱ = 200.0f;
        this.ˋॱ = 180;
        this.ͺ = 0;
        this.ˏॱ = 490.0d;
        this.ॱˋ = false;
        this.ᐝॱ = true;
        this.ॱ = 0;
        this.ॱᐝ = new Handler(this) {
            final /* synthetic */ WbSdkProgressBar ॱ;

            {
                this.ॱ = r1;
            }

            public void handleMessage(Message message) {
                super.handleMessage(message);
                switch (message.what) {
                    case 0:
                        this.ॱ.ᐝॱ = false;
                        return;
                    default:
                        return;
                }
            }
        };
        this.ˏ = ˏ(context, 50);
        this.ˋ = ˏ(context, 5);
        this.ˊ = ˏ(context, 3);
        this.ॱॱ = new Paint();
        this.ॱॱ.setAntiAlias(true);
        this.ॱॱ.setColor(-48861);
        this.ॱॱ.setStyle(Style.STROKE);
        this.ॱॱ.setStrokeWidth((float) this.ˋ);
        this.ˎ = new RectF((float) this.ˊ, (float) this.ˊ, (float) (this.ˏ - this.ˊ), (float) (this.ˏ - this.ˊ));
    }

    private int ˏ(Context context, int i) {
        return (int) (context.getResources().getDisplayMetrics().density * ((float) i));
    }

    protected synchronized void onDraw(Canvas canvas) {
        long abs = Math.abs(SystemClock.uptimeMillis() - this.ॱˊ) % 360;
        float f = (this.ˊॱ * ((float) abs)) / 1000.0f;
        ॱ(abs);
        this.ॱˊ = SystemClock.uptimeMillis();
        this.ʽ += f;
        if (this.ʽ >= 360.0f) {
            this.ʽ -= 360.0f;
        }
        canvas.drawArc(this.ˎ, this.ʽ - 90.0f, this.ʼ + 20.0f, false, this.ॱॱ);
        if (this.ᐝॱ) {
            if (VERSION.SDK_INT >= 21) {
                postInvalidate();
            } else {
                invalidate();
            }
        }
    }

    public void setProgressColor(int i) {
        this.ॱॱ.setColor(i);
    }

    protected void onVisibilityChanged(View view, int i) {
        super.onVisibilityChanged(view, i);
        if (i == 8) {
            this.ॱᐝ.sendEmptyMessageDelayed(0, 1000);
        } else if (i == 0 && getVisibility() == 0) {
            this.ॱᐝ.removeMessages(0);
            this.ᐝॱ = true;
            invalidate();
        }
    }

    private void ॱ(long j) {
        if (this.ͺ >= this.ˋॱ) {
            this.ʻॱ += (double) j;
            if (this.ʻॱ >= this.ˏॱ) {
                this.ʻॱ -= this.ˏॱ;
                this.ͺ = 0;
                this.ॱˋ = !this.ॱˋ;
            }
            float cos = (((float) Math.cos(((this.ʻॱ / this.ˏॱ) + 1.0d) * 3.141592653589793d)) / 2.0f) + 0.5f;
            if (this.ॱˋ) {
                cos = (1.0f - cos) * ((float) 280);
                this.ʽ += this.ʼ - cos;
                this.ʼ = cos;
                return;
            }
            this.ʼ = cos * ((float) 280);
            return;
        }
        this.ͺ += j;
    }

    protected void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        setMeasuredDimension(this.ˏ, this.ˏ);
    }
}
